<?php

namespace App\Service\Wechat;

use Illuminate\Database\Eloquent\Model;

class Send extends Model
{
    //
    protected $table = 'wx_send_log';


    public function content(){
        return $this->hasMany('App\Service\Wechat\MaterialNewsContent','log_id','id');
    }
    public static function sendLog($data,$contents){
        $model = new Send();
        $model->type = $data['type'];
        $model->media_id = $data['media_id'];
        $model->save();
        $contentData = [];
        foreach ($contents as $content){
            $contentData[] = new SendNewsContent(
                [
                    'title' =>  $content['title'],
                    'digest'    =>  $content['digest'],
                    'thumb_media_id'    =>  $content['thumb_media_id'],
                    'show_cover_pic'    =>  $content['show_cover_pic'],
                    'content_source_url'   =>  $content['content_source_url'],
                ]
            );
        }
        if($contentData){
            $model->content()->saveMany($contentData);
        }
    }
}
